package java6681.borrow;

public class Library6681 {
    private Book6681[] bookList;
    private String name;

    public Library6681() {
    }

    public Library6681(Book6681[] bookList, String name) {
        this.bookList = bookList;
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Book6681[] getBookList() {
        return bookList;
    }

    public void setBookList(Book6681[] bookList) {
        this.bookList = bookList;
    }

    public Book6681 borrow(String name) {
        for (int i = 0; i < bookList.length; i++) {
            if (bookList[i].getName().equals(name)) {
                return bookList[i];
            }
        }
        return null;
    }

    public String borrow(Book6681[] books) {
        if (books == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder();

        for (int j = 0; j < bookList.length; j++) {
            for (int i = 0; i < books.length; i++) {
                if (bookList[j].equals(books[i])) {
                    if (i != books.length - 1) {
                        sb.append(",");
                    } else {
                        sb.append(",");
                    }
                    sb.append(books[i]);
                }
            }
        }
        sb.deleteCharAt(0);
        return String.valueOf(sb);
    }

    @Override
    public String toString() {
        return name;
    }
}
